def compare_text_files(file1_path, file2_path):
    with open(file1_path, 'r') as file1, open(file2_path, 'r') as file2:
        # 读取所有行，并去除每行末尾的空白字符（如 \n）
        lines1 = [line.rstrip() for line in file1]
        lines2 = [line.rstrip() for line in file2]

    max_lines = max(len(lines1), len(lines2))
    differences = []

    for i in range(max_lines):
        line1 = lines1[i] if i < len(lines1) else None
        line2 = lines2[i] if i < len(lines2) else None

        if line1 is None:
            differences.append((i + 1, "文件1缺失", line2))
        elif line2 is None:
            differences.append((i + 1, line1, "文件2缺失"))
        elif line1 != line2:
            differences.append((i + 1, line1, line2))

    return differences

def print_differences(differences):
    if not differences:
        print("两个文件内容完全相同！")
        return

    print("发现差异的行：")
    for line_num, content1, content2 in differences:
        print(f"行 {line_num}:")
        if content1 == "文件1缺失":
            print(f"  文件1缺失 → 文件2内容: {content2}")
        elif content2 == "文件2缺失":
            print(f"  文件1内容: {content1} → 文件2缺失")
        else:
            print(f"  文件1: {content1}")
            print(f"  文件2: {content2}")
        print("-" * 40)

# 示例用法
if __name__ == "__main__":
    # file1 = input("请输入第一个文件的路径: ")
    # file2 = input("请输入第二个文件的路径: ")
    file1 = 'my.out'
    file2 = 'problem/1.out'

    differences = compare_text_files(file1, file2)
    print_differences(differences)